<%@page import="dao.CheckAccount"%>
<%@page import="dao.MngClass"%>
<%@page import="beans.ClassBean"%>
<%@page import="beans.FeedBackBean"%>
<%@page import="dao.FeedBackDAO"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>FeedBack</title>

        <script language="javascript">
            function delete1()
            {
                return confirm('Do you want delete this record');
            }
        </script>
        <style>                        
            table, th, td {
                border: 1px solid #619702;
                border-collapse: collapse;
                width:99.3% ;
            }
            th, td {
                padding: 5px;
                width: 100px;
            }
            th {
                text-align: center;
            }
        </style>
    </head>

    <body>
        FeedBack Management <br><br>
        <br>
        <form action="editFeedBack" method="get">
            <input type="hidden" name="action" value="show_by_class">
            <select name="class_id">
                <option value="">Select Class</option>
                <%
                    MngClass mngClass = new MngClass();
                    List<ClassBean> listClass = mngClass.showClass();
                    for (ClassBean classBean : listClass) {
                %>
                <option value="<%= classBean.getClass_id()%>"><%= classBean.getClass_name()%></option>
                <% }%>
            </select>
            <input type="submit" value="Show" >
        </form>       
        <br> <br>
        <%
            if (request.getAttribute("msg") != null) {
        %>
        <font color="green" > <%= request.getAttribute("msg")%> </font>
        <%
            }
             if (request.getAttribute("error") != null) {
        %>
        <font color="red" > <%= request.getAttribute("error")%> </font>
        <%
            }
        
            HttpSession sessionfeedback = request.getSession();
            String roll_feed_back = sessionfeedback.getAttribute("roll").toString();
            String staff_id = sessionfeedback.getAttribute("acc_id").toString();
            List<ClassBean> listClassById = mngClass.listClassByAccId(staff_id);
            FeedBackDAO fbDAO = new FeedBackDAO();
            List<FeedBackBean> listFeedBack = null;
            if ((request.getAttribute("class_id") == null) || request.getAttribute("class_id").toString().equals("")) {
                if (roll_feed_back.equals("admin")) {
                    listFeedBack = fbDAO.showFeedBack();
                } else if (roll_feed_back.equals("staff")) {
                    listFeedBack = fbDAO.showFeedBackByClass(listClassById);
                }
            } else {
                listFeedBack = fbDAO.showFeedBackByClassID(request.getAttribute("class_id").toString());
            }
            CheckAccount ck = new CheckAccount();
        %>
        <table>                
            <tr>
                <th>Student</th>
                <th>Question</th>		
                <th>Answer</th>
                <th>Class</th>
                    <%
                        if (roll_feed_back.equals("staff")) {
                    %>
                <th>Answer</th>
                <th>Delete</th>
                    <%
                        }
                    %>                
            </tr> 
            <%  for (FeedBackBean FBBean : listFeedBack) {
                    if (FBBean.getAnswer() == null) {
                        FBBean.setAnswer("");
                    }
            %>
            <tr>
                <th><%= ck.getFullName(FBBean.getAcc_id())%></th>
                <th><%= FBBean.getQuestion()%></th>		
                <th><%= FBBean.getAnswer()%></th>
                <th><%= mngClass.getClassName(FBBean.getClass_id())%></th>
                    <%
                        if (roll_feed_back.equals("staff")) {
                    %>
                <th>
            <form action="editFeedBack" method ="get">
                <input type="hidden" name="action" value="update">
                <input type="hidden" name="feedback_id" value="<%= FBBean.getFeedback_id()%>">   
                <input type="hidden" name="acc_id" value="<%= FBBean.getAcc_id()%>"> 
                <input type="hidden" name="question" value="<%= FBBean.getQuestion()%>">
                <input type="hidden" name="answer" value="<%= FBBean.getAnswer()%>">
                <input type="hidden" name="class_id" value="<%= FBBean.getClass_id()%>">                   
                <input type="submit" value="Answer">
            </form>
        </th>
        <th>
        <form action="editFeedBack" method ="get">
            <input type="hidden" name="action" value="delete">
            <input type="hidden" name="feedback_id" value="<%= FBBean.getFeedback_id()%>">
            <input type="submit" value="Delete" onclick='return delete1()'>
        </form>
    </th>
    <%
        }
    %>     
</tr>   
<%
    }
%>
</table>
</body>
</html>
